<template>
  <div v-if="activity.status != null" class="activity-item-container">
    <div class="activity-item">
      <!-- Badge for Status -->
      <div class="status-badge">
        <el-tag
          :type="statusMap[activity.status]?.type || 'info'"
          class="status-tag"
          effect="dark"
          size="small"
        >
          {{ statusMap[activity.status]?.text || "未知状态" }}
        </el-tag>
      </div>

      <!-- Image Container with Overlay Effect -->
      <div class="img-container">
        <div class="img-view">
          <img :src="activity.cover" :alt="activity.title" />
          <div class="img-overlay">
            <div class="view-details">查看详情</div>
          </div>
        </div>
      </div>

      <!-- Info Section -->
      <div class="info-view">
        <h3 class="activity-name">{{ activity.title }}</h3>

        <div class="info-grid">
          <!-- Category with Icon -->
          <div class="info-item">
            <div class="info-icon category-icon">
              <svg
                xmlns="http://www.w3.org/2000/svg"
                viewBox="0 0 24 24"
                width="16"
                height="16"
                fill="none"
                stroke="currentColor"
                stroke-width="2"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path
                  d="M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.93a2 2 0 0 1-1.66-.9l-.82-1.2A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13c0 1.1.9 2 2 2Z"
                ></path>
              </svg>
            </div>
            <div class="info-content">
              <div class="info-label">类别</div>
              <div class="info-value category-value">
                {{ activity.categoryName }}
              </div>
            </div>
          </div>

          <!-- Participants Count with Icon -->
          <div class="info-item">
            <div class="info-icon participants-icon">
              <svg
                xmlns="http://www.w3.org/2000/svg"
                viewBox="0 0 24 24"
                width="16"
                height="16"
                fill="none"
                stroke="currentColor"
                stroke-width="2"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"></path>
                <circle cx="9" cy="7" r="4"></circle>
                <path d="M22 21v-2a4 4 0 0 0-3-3.87"></path>
                <path d="M16 3.13a4 4 0 0 1 0 7.75"></path>
              </svg>
            </div>
            <div class="info-content">
              <div class="info-label">报名人数</div>
              <div class="info-value">{{ activity.registerCount }}</div>
            </div>
          </div>

          <!-- Time Period with Icon -->
          <div class="info-item full-width">
            <div class="info-icon time-icon">
              <svg
                xmlns="http://www.w3.org/2000/svg"
                viewBox="0 0 24 24"
                width="16"
                height="16"
                fill="none"
                stroke="currentColor"
                stroke-width="2"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <circle cx="12" cy="12" r="10"></circle>
                <polyline points="12 6 12 12 16 14"></polyline>
              </svg>
            </div>
            <div class="info-content">
              <div class="info-label">时间</div>
              <div class="info-value time-value">
                {{ formatTimeRange(activity.startTime, activity.endTime) }}
              </div>
            </div>
          </div>

          <!-- Location with Icon -->
          <div class="info-item full-width">
            <div class="info-icon location-icon">
              <svg
                xmlns="http://www.w3.org/2000/svg"
                viewBox="0 0 24 24"
                width="16"
                height="16"
                fill="none"
                stroke="currentColor"
                stroke-width="2"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M20 10c0 6-8 12-8 12s-8-6-8-12a8 8 0 0 1 16 0Z"></path>
                <circle cx="12" cy="10" r="3"></circle>
              </svg>
            </div>
            <div class="info-content">
              <div class="info-label">地址</div>
              <div class="info-value location-value">
                {{ activity.detailAddress }}
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { defineProps, computed } from "vue";

const props = defineProps({
  activity: {
    type: Object,
    required: true,
  },
});
// 活动状态
const statusMap = {
  0: { text: "未发布", type: "info" },
  1: { text: "已发布", type: "success" },
  2: { text: "签到中", type: "warning" },
};

// Format time range to be more readable
const formatTimeRange = (startTime, endTime) => {
  if (!startTime || !endTime) return "";

  // Simple formatting - this can be enhanced with proper date formatting libraries if needed
  return `${startTime} ~ ${endTime}`;
};
</script>

<style scoped>
/* Container for consistent sizing */
.activity-item-container {
  height: 100%;
  cursor: pointer;
}

/* Main Card Styling */
.activity-item {
  display: flex;
  flex-direction: column;
  height: 100%;
  border-radius: 24px;
  background: #ffffff;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.06);
  transition: all 0.4s cubic-bezier(0.215, 0.61, 0.355, 1);
  overflow: hidden;
  position: relative;
}

.activity-item:hover {
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.12);
  transform: translateY(-6px);
}

/* Status Badge */
.status-badge {
  position: absolute;
  top: 16px;
  right: 16px;
  padding: 6px 14px;
  border-radius: 30px;
  font-size: 13px;
  font-weight: 600;
  z-index: 10;
}

.status-badge:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 102, 255, 0.25);
}

/* Status Badge Colors */
.status-active {
  background: linear-gradient(135deg, #0066ff, #5cacff);
}

.status-finished {
  background: linear-gradient(135deg, #666666, #8e8e93);
}

.status-cancelled {
  background: linear-gradient(135deg, #ff3b30, #ff6b6b);
}

.status-applied {
  background: linear-gradient(135deg, #00b649, #34d07c);
}

.status-enrolling {
  background: linear-gradient(135deg, #ff9500, #ffb340);
}

.status-default {
  background: linear-gradient(135deg, #5856d6, #7b79e5);
}

/* Image Section */
.img-container {
  position: relative;
  width: 100%;
  padding-top: 56.25%; /* 16:9 Aspect Ratio */
  overflow: hidden;
}

.img-view {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.img-view img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.7s cubic-bezier(0.215, 0.61, 0.355, 1);
}

/* Image Overlay with Animation */
.img-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    to top,
    rgba(0, 0, 0, 0.7) 0%,
    rgba(0, 0, 0, 0) 60%
  );
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 20px;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.activity-item:hover .img-view img {
  transform: scale(1.08);
}

.activity-item:hover .img-overlay {
  opacity: 1;
}

.view-details {
  color: white;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  padding: 8px 16px;
  border-radius: 30px;
  font-size: 14px;
  font-weight: 500;
  transform: translateY(10px);
  opacity: 0;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) 0.1s;
}

.activity-item:hover .view-details {
  transform: translateY(0);
  opacity: 1;
}

/* Info Section Styling */
.info-view {
  display: flex;
  flex-direction: column;
  padding: 24px;
  flex: 1;
}

.activity-name {
  font-size: 20px;
  font-weight: 700;
  color: #1d1d1f;
  margin: 0 0 20px 0;
  line-height: 1.4;
  letter-spacing: -0.3px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  max-height: 56px;
}

/* Info Grid Layout */
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.info-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.full-width {
  grid-column: 1 / -1;
}

/* Icon Styling */
.info-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
}

.category-icon {
  color: #5856d6;
  background-color: rgba(88, 86, 214, 0.1);
}

.participants-icon {
  color: #ff9500;
  background-color: rgba(255, 149, 0, 0.1);
}

.time-icon {
  color: #0066ff;
  background-color: rgba(0, 102, 255, 0.1);
}

.location-icon {
  color: #ff3b30;
  background-color: rgba(255, 59, 48, 0.1);
}

/* Info Content Styling */
.info-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0; /* For text overflow to work */
}

.info-label {
  font-size: 13px;
  color: #86868b;
  font-weight: 500;
}

.info-value {
  font-size: 15px;
  color: #1d1d1f;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Special styling for location that might need two lines */
.location-value {
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.4;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .info-grid {
    grid-template-columns: 1fr;
  }

  .full-width {
    grid-column: auto;
  }
}

/* For very small screens */
@media (max-width: 480px) {
  .status-badge {
    top: 12px;
    right: 12px;
    padding: 4px 12px;
    font-size: 12px;
  }

  .info-view {
    padding: 20px;
  }

  .activity-name {
    font-size: 18px;
    margin-bottom: 16px;
  }
}
</style>
